package com.momoc.mrpc.register;

import com.alibaba.nacos.api.exception.NacosException;
import com.alibaba.nacos.api.naming.pojo.Instance;
import com.momoc.mrpc.register.definition.MRpcRegDefinition;
import java.util.Collection;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

/**
 * @author momoc
 * @version 1.0
 * @className RegisterContext
 * @description
 * @date 2022/7/25 6:50 下午
 */

@Component
public class RegisterContext  {


    @Autowired
    RegisterCenter registerCenter;



    //接口对服务名
    static Map<String, List<String>> className2Service= new HashMap<>();
    //变化
    static Map<String, String> className2String= new HashMap<>();

    //用来注册的数据
    public static Map<String, MRpcRegDefinition> registerServiceMap= new HashMap<>();
    //映射 接口数据
    public static Map<String, MRpcRegDefinition> rpcNameServiceMap = new HashMap<String, MRpcRegDefinition>();

    static Collection<Instance> onlineServer;



    public  void finishScans() {
        try {
            registerCenter.register(registerServiceMap);
        } catch (NacosException e) {
            e.printStackTrace();
        }
    }

    public static Map<String, List<String>> getClassName2Service() {
        return className2Service;
    }

    public static Map<String, MRpcRegDefinition> getRpcNameServiceMap() {
        return rpcNameServiceMap;
    }

    public static Map<String, String> getClassName2String() {
        return className2String;
    }

    public static Collection<Instance> getOnlineServer() {
        return onlineServer;
    }

    public static void setOnlineServer(Collection<Instance> onlineServer) {
        RegisterContext.onlineServer = onlineServer;
    }


}
